import { Injectable } from '@angular/core';
import { ApolloQueryResult, FetchResult } from '@apollo/client/core';
import { Apollo, gql, QueryRef } from 'apollo-angular';
import { Observable } from 'rxjs';
import { AccountConfigServiceApi,
AccountConfigService_currentAccountResult,
AccountConfigService_listResult,
AccountConfigService_listVariables,
AccountConfigService_totalCountResult,
AccountConfigService_searchResult,
AccountConfigService_searchVariables,
AccountConfigService_loadAllResult,
AccountConfigService_getByIdResult,
AccountConfigService_getByIdVariables,
AccountConfigService_addSpaceResult,
AccountConfigService_addSpaceVariables,
AccountConfigService_createAccountResult,
AccountConfigService_saveResult,
AccountConfigService_saveVariables,
AccountConfigService_removeByIdResult,
AccountConfigService_removeByIdVariables,
AccountConfigService_removeByIdListResult,
AccountConfigService_removeByIdListVariables,
AccountConfigResultInfo, AccountConfigPageInfo,
AccountConfigConnection,
AccountConfigPackage,
AccountConfigOrderBy,
AccountConfigMutationInfo,
AccountConfigStringFilter,
AccountConfigNumberFilter,
AccountConfigBooleanFilter,
accountConfigServiceQuery,
accountConfigServiceMutation,
AccountConfigServiceQueryOptions,
AccountConfigStore,
AccountConfigView,
AccountConfigInput,
AccountConfigFilter,
AccountConfigErrorBody} from '../model/account_config_service.model';

/************************************************************************
 * 账户信息
 */
@Injectable({
    providedIn: 'root'
})
export class AccountConfigService implements AccountConfigServiceApi {

        private currentAccountGql:string;
        private listGql:string;
        private totalCountGql:string;
        private searchGql:string;
        private searchObjectRef: QueryRef<AccountConfigService_searchResult>;
        private loadAllGql:string;
        private getByIdGql:string;

    constructor(private apollo: Apollo) {
        this.currentAccountGql=`query nars_accountConfigService_currentAccount{${accountConfigServiceQuery.accountConfigService_currentAccount}}`;
        this.listGql=`query nars_accountConfigService_list($filter: AccountConfigFilter!,$orderBy: OrderBy){${accountConfigServiceQuery.accountConfigService_list}}`;
        this.totalCountGql=`query nars_accountConfigService_totalCount{${accountConfigServiceQuery.accountConfigService_totalCount}}`;
        this.searchGql=`query nars_accountConfigService_search($first: Int!,$offset: Float!,$filter: AccountConfigFilter!,$orderBy: OrderBy){${accountConfigServiceQuery.accountConfigService_search}}`;
        this.searchObjectRef = apollo.watchQuery<AccountConfigService_searchResult>({ query: gql`${this.searchGql}`, fetchPolicy:'cache-first' });
        this.loadAllGql=`query nars_accountConfigService_loadAll{${accountConfigServiceQuery.accountConfigService_loadAll}}`;
        this.getByIdGql=`query nars_accountConfigService_getById($id: String!){${accountConfigServiceQuery.accountConfigService_getById}}`;
    }
    /**
     * 获取当前账号
     */
    currentAccount(options:AccountConfigServiceQueryOptions = { cachePolicy: 'no-cache', more: false }): Observable<ApolloQueryResult<AccountConfigService_currentAccountResult>> {
            return this.apollo.query({ query: gql`${this.currentAccountGql}`,fetchPolicy:options.cachePolicy});
    }
    /**
     * 分页查询
     */
    list(variables: AccountConfigService_listVariables, options:AccountConfigServiceQueryOptions = { cachePolicy: 'no-cache', more: false }): Observable<ApolloQueryResult<AccountConfigService_listResult>> {
            return this.apollo.query({ query: gql`${this.listGql}`,variables ,fetchPolicy:options.cachePolicy});
    }
    /**
     * 统计库中所有对象的数据量
     */
    totalCount(options:AccountConfigServiceQueryOptions = { cachePolicy: 'no-cache', more: false }): Observable<ApolloQueryResult<AccountConfigService_totalCountResult>> {
            return this.apollo.query({ query: gql`${this.totalCountGql}`,fetchPolicy:options.cachePolicy});
    }
    /**
     * 游标查询
     */
    search(variables: AccountConfigService_searchVariables, options:AccountConfigServiceQueryOptions = { cachePolicy: 'cache-first', more: false }): Observable<ApolloQueryResult<AccountConfigService_searchResult>> {
        this.searchObjectRef.setVariables(variables);
        if(options.more){
            this.searchObjectRef.fetchMore({variables});
        }
        return this.searchObjectRef.valueChanges;
    }
    /**
     * 获取库中所有数据，数据量大时请谨慎使用
     */
    loadAll(options:AccountConfigServiceQueryOptions = { cachePolicy: 'cache-first', more: false }): Observable<ApolloQueryResult<AccountConfigService_loadAllResult>> {
            return this.apollo.query({ query: gql`${this.loadAllGql}`,fetchPolicy:options.cachePolicy});
    }
    /**
     * 获取一个对象
     */
    getById(variables: AccountConfigService_getByIdVariables, options:AccountConfigServiceQueryOptions = { cachePolicy: 'cache-first', more: false }): Observable<ApolloQueryResult<AccountConfigService_getByIdResult>> {
            return this.apollo.query({ query: gql`${this.getByIdGql}`,variables ,fetchPolicy:options.cachePolicy});
    }
    /**
     * 添加空间
     */
    addSpace(variables: AccountConfigService_addSpaceVariables): Observable<FetchResult<AccountConfigService_addSpaceResult>>{
        return this.apollo.mutate({mutation: gql`mutation nars_accountConfigService_addSpace($: String!,$: Float!){${accountConfigServiceMutation.accountConfigService_addSpace}}`, variables,fetchPolicy:'no-cache'});
    }
    /**
     * 创建账户
     */
    createAccount(): Observable<FetchResult<AccountConfigService_createAccountResult>>{
        return this.apollo.mutate({mutation: gql`mutation nars_accountConfigService_createAccount{${accountConfigServiceMutation.accountConfigService_createAccount}}`, variables,fetchPolicy:'no-cache'});
    }
    /**
     * 保存对象
     */
    save(variables: AccountConfigService_saveVariables): Observable<FetchResult<AccountConfigService_saveResult>>{
        return this.apollo.mutate({mutation: gql`mutation nars_accountConfigService_save($entity: AccountConfigInput!){${accountConfigServiceMutation.accountConfigService_save}}`, variables,fetchPolicy:'no-cache'});
    }
    /**
     * 删除一个对象
     */
    removeById(variables: AccountConfigService_removeByIdVariables): Observable<FetchResult<AccountConfigService_removeByIdResult>>{
        return this.apollo.mutate({mutation: gql`mutation nars_accountConfigService_removeById($id: String!){${accountConfigServiceMutation.accountConfigService_removeById}}`, variables,fetchPolicy:'no-cache'});
    }
    /**
     * 删除一批对象
     */
    removeByIdList(variables: AccountConfigService_removeByIdListVariables): Observable<FetchResult<AccountConfigService_removeByIdListResult>>{
        return this.apollo.mutate({mutation: gql`mutation nars_accountConfigService_removeByIdList($ids: [String]!){${accountConfigServiceMutation.accountConfigService_removeByIdList}}`, variables,fetchPolicy:'no-cache'});
    }









}
